package com.qhy.service.imp;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.qhy.mapper.CountComMapper;
import com.qhy.mapper.TbCommentsMapper;
import com.qhy.mapper.ViewComMapper;
import com.qhy.pojo.CountCom;
import com.qhy.pojo.CountComExample;
import com.qhy.pojo.CountComExample.Criteria;
import com.qhy.pojo.TbComments;
import com.qhy.pojo.ViewCom;
import com.qhy.pojo.ViewComExample;
import com.qhy.service.IComService;


@Service
public class ComService implements IComService {
	
	@Resource
	private CountComMapper countMapper;
	
	@Resource
	private ViewComMapper viewMapper;
	
	@Resource
	private TbCommentsMapper mapper;
	
	public CountCom queryNumById(Integer ps_id) {
		CountComExample example = new CountComExample();
		Criteria criteria = example.createCriteria();
		criteria.andCmPsIdEqualTo(ps_id);
		List<CountCom> list = countMapper.selectByExample(example);
		return list.size()>0?list.get(0):null;
	}


	public List<ViewCom> queryByPsId(Integer ps_id) {
		ViewComExample example = new ViewComExample();
		com.qhy.pojo.ViewComExample.Criteria criteria = example.createCriteria();
		criteria.andCmPsIdEqualTo(ps_id);
		return viewMapper.selectByExample(example);
	}


	public int addCom(TbComments comments) {
		comments.setCmTime(new Date());
		return mapper.insert(comments);
	}


	public int deleteCom(Integer cmId) {
		return mapper.deleteByPrimaryKey(cmId);
	}


	public List<ViewCom> queryByUsId(int us_id) {
		ViewComExample example = new ViewComExample();
		com.qhy.pojo.ViewComExample.Criteria criteria = example.createCriteria();
		criteria.andCmUsIdEqualTo(us_id);
		return viewMapper.selectByExample(example);
	}

	
	
	
	
	
}
